<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	</head>
	<body>
	<?php 
					$daction = $_SESSION['action'];
		include 'operations/connection.php';
		session_start();
		$lang = $_SESSION['lang'];
		//Get information of document
		$query = mysql_query("select a.Tile,a.Content,a.Timecreate,a.TripDate,a.purpose,a.Content2,a.Description,a.comment,
				e.Fullname,a.IDGroupApprove,a.IDStatus
				from approvedoc a inner join employee e on a.IDEmployee = e.IDEmployee 
				where a.IDApproveDoc = '$id'");
		while ($row = mysql_fetch_array($query))
		{
			$dcomment = $row[comment];
			$dtitle = $row[Tile];
			$ddescription = $row[Description];
			$dtime = $row[Timecreate];
			$duser = $row[Fullname];
			$demployeeperforment = $row[EmployeePerforment];
			$dtripdate = $row[TripDate];
			$dlocation = $row[Location];
			$dtotaltime = $row[TotalTime];
			$didgroupapprover = $row[IDGroupApprove];
			$dcontent = $row[Content];
			$dcontent2 = $row[Content2];
			$dpurpose = $row[purpose];
			$didemployee = $row[IDEmployee];
			$dstatus = $row[IDStatus];
		}
		
		$queryEmployee = mysql_query("SELECT e.FullName,dl.DepartmentName,e.Position
				FROM employee e INNER JOIN department_lang dl ON dl.IDDepartment = e.IDDepartment
				WHERE e.IDEmployee = '$didemployee' AND dl.LangID = '$lang'");
		while ($row = mysql_fetch_array($queryEmployee))
		{
			$dnameemployee = $row[FullName];
			$dnamedepartment = $row[DepartmentName];
			$dposition = $row[Position];
		}
	?>
	<div class="main_content">
		<ul class="top_but">
			<li><a  class="back-button"><img src="images/back.png" alt="" /></a><p class="hidden">Back</p></li>
				<?php if($daction=="re_not_approve"){?>
				<li><a href="<?echo approve($didgroupapprover, $id_employee)?>"><img src="images/approval.png" alt="" /></a><p class="hidden">Approve</p></li>
				<li><a href="<?echo reject($didgroupapprover, $id_employee)?>"><img src="images/reject.png" alt="" /></a><p class="hidden">Reject</p></li>
				<?php }?>
				<?php
					if($daction == "re_reference_waiting"){
				?>
					<li><a href="<?echo viewReference($didgroupapprover, $id_employee)?>"><img src="images/approval.png" alt="" /></a><p class="hidden">Accept</p></li>
				<?php }?>
		</ul>
		<table class="tcontent" cellpadding="5" cellspacing="0">
			<tr>
				<td class="col_left" width="15%"><?=$l_approver?></td>
				<td colspan="3">
				<table style="width: 100%;" cellpadding="5" cellspacing="0">
					<tr>
						<td><?=$l_step?></td>
						<td>
						<?
						//Get group approver
						$query1 = mysql_query("SELECT st.IDConfigStaticLang,l.DateApprove,e.Fullname FROM listapprove l
							INNER JOIN employee e ON l.IDEmployee = e.IDEmployee
							INNER JOIN `status` st ON l.IDStatus = st.IDStatus
							WHERE CONVERT(l.IDGroupApprove USING utf8) = CONVERT('$didgroupapprover' USING utf8)
							ORDER BY l.Order ASC");
							while ($row = mysql_fetch_array($query1))
							{
								$dnameapprover = $row[Fullname];
								if ($row[IDConfigStaticLang] == 8){
									$dstatus=$l_status_complete;
								} else if ($row[IDConfigStaticLang] == 9){
									$dstatus=$l_status_pending;
								} else if ($row[IDConfigStaticLang] == 10){
									$dstatus=$l_status_declined;
								} else if ($row[IDConfigStaticLang] == 11){
									$dstatus=$l_status_saved;
								} else if ($row[IDConfigStaticLang] == 20){
									$dstatus=$l_status_reference;
								}
						?>
						<span style="display: block;">
							<b><?=$dnameapprover?></b>_<?=$dstatus?>
						</span>
						<?
						}
						?>
						</td>
						<td>
							<?
							//Get list references
							$query2 = mysql_query("SELECT e.Fullname FROM list_reference l
								INNER JOIN employee e ON l.id_employee = e.IDEmployee
								WHERE CONVERT(l.id_group USING utf8) = CONVERT('$didgroupapprover' USING utf8)");
							while ($row = mysql_fetch_array($query2))
							{
								$dnamereferences = $row[Fullname];
							?>
							<b><?=$dnamereferences?></b>;
							<?}?>
						</td>
					</tr>
				</table>
				</td>
			</tr>
			<tr>
				<td class="col_left" width="15%"><?=$l_department?>/<?=$l_employee?></td>
				<td colspan="3"><?=$dnameemployee?> (<?=$dnamedepartment?>)</td>
			</tr>
			<tr>
				<td class="col_left" width="15%"><?=$l_title?></td>
				<td colspan="3"><?=$dtitle?></td>
			</tr>
			<tr>
				<td class="col_left"><?=$l_content?></td>
				<td colspan="3">
					<?=$dcontent?>
				</td>
			</tr>
			<tr>
				<td class="col_left"><?=$l_created_date?></td>
				<td><?=$dtime?></td>
				<td class="col_left"><?=$l_purchase_date?></td>
				<td><?=$dtripdate?></td>
			</tr>
			<tr>
				<td class="col_left"><?=$l_purpose?></td>
				<td colspan="3"><?=$dpurpose?></td>
			</tr>
			<tr>
				<td class="col_left"><?=$l_project?></td>
				<td colspan="3"><?=$dcontent2?></td>
			</tr>
			<tr>
				<td class="col_left"><?=$l_description?></td>
				<td colspan="3"><?=$ddescription?></td>
			</tr>
		</table>
		<table class="list_ref" cellpadding="5" cellspacing="0">
			<tr>
				<th><?=$l_product_item?></th>
				<th><?=$l_company_name?></th>
				<th><?=$l_quantity?></th>
				<th><?=$l_price?></th>
				<th><?=$l_price_vat?></th>
				<th><?=$l_total_amount?></th>
			</tr>
			<?
			$querybuy = mysql_query("select * from buying_document where document_id = '$id'");
			$dtotalamountt = 0;
			while ($row = mysql_fetch_array($querybuy))
			{
				$dproductitem = $row[name];
				$dcompanyname = $row[company];
				$dquantity = $row[amount];
				$dprice = $row[price];
				$dpricevat = $row[vat];
				$dtotalamount = $row[total];
				$dtotalamountt = $dtotalamount + $dtotalamountt;
			?>
			<tr>
				<td><?=$dproductitem?></td>
				<td><?=$dcompanyname?></td>
				<td><?=$dquantity?></td>
				<td><?=$dprice?></td>
				<td><?=$dpricevat?></td>
				<td style="text-align:right;padding-right:10px;"><?=$dtotalamount?></td>
			</tr>
			<?
			}
			?>
		</table>
		<table class="tcontent" cellpadding="5" cellspacing="0">
			<tr>
				<td class="col_left" width="15%"><?=$l_total_amount?></td>
				<td style="text-align:right;font-weight:bold;padding-right:10px;"><?=$dtotalamountt?></td>
			</tr>
			<tr>
				<td class="col_left"><?=$l_comment?></td>
				<td style="text-align:left;">
					<?=$dcomment?>
				</td>
			</tr>
		</table>
	</div>
	</body>
    <?php mysql_close($connection);?>
</html>